﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace _04_TableLayoutPanel_PictureBox
{
    public partial class Form1 : Form
    {
        //定义数组用来存储指定路径下的所有图片
        string[] imageURL = null;
        //定义一个变量用来存储当前图片的索引
        int index = 0;  

        public Form1()
        {
            InitializeComponent();
            //读取指定路径下的所有图片
            imageURL = Directory.GetFiles(@"./xing");
        }
        /// <summary>
        /// 下一张
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //判断是否达到了最大值，如果没有达到最大值，就让索引+1
            if (index < imageURL.Length - 1)
            {
                this.pictureBox1.ImageLocation = imageURL[++index];
            }
            else
            {
                index = 0;
                this.pictureBox1.ImageLocation = imageURL[index];
            }
        }
        /// <summary>
        /// 上一张
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (index == 0)
            {
                this.pictureBox1.ImageLocation = imageURL[0];
                index = imageURL.Length - 1;
            }
            else
            {
                this.pictureBox1.ImageLocation = imageURL[--index];
            }
        }
    }
}
